package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * 匹配钉钉模板字段类型
 *
 * 每种表单组件的component_name都是固定的。表单组件的props里的id，必须在模板里唯一，可以有两段字符串组成，第一段为表单的component_name；第二段为8位随机字符串
 *
 * @author xingxing.xiao
 */
@Getter
public enum DingtalkFieldTypeEnum {

    TEXT(1, "enum.dingtalkFieldType.name.text", "TextField"),
    NUM(2, "enum.dingtalkFieldType.name.num", "NumberField"),
    COMBO(3, "enum.dingtalkFieldType.name.combo", "DDSelectField"),
    DATE(4, "enum.dingtalkFieldType.name.date", "DDDateField"),
    IMAGE(6, "enum.dingtalkFieldType.name.image", "DDPhotoField"),
    TEXTAREA(7, "enum.dingtalkFieldType.name.textarea", "TextareaField"),
    UPLOAD(8, "enum.dingtalkFieldType.name.upload", "DDAttachment"),
    CHECKBOX(9, "enum.dingtalkFieldType.name.checkbox", "DDMultiSelectField"),
    UNKNOWN(404, "enum.dingtalkFieldType.name.unknown", "unknown");

    private final int type;
    private final String name;
    private final String alias;

    private DingtalkFieldTypeEnum(int type, String name, String alias) {
        this.type = type;
        this.name = name;
        this.alias = alias;
    }

    public static DingtalkFieldTypeEnum getByCode(Integer type) {
        DingtalkFieldTypeEnum[] var1 = values();
        int var2 = var1.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            DingtalkFieldTypeEnum cacheCode = var1[var3];
            if (type.equals(cacheCode.getType())) {
                return cacheCode;
            }
        }

        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
